home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 7.2 KB | 292 lines | [TEXT/MPS ] |
- {$P}
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UMacApp.TDeskScrapView.p }
- { Copyright © 1985-1990 Apple Computer, Inc. All rights reserved. }
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAInit}
-
- PROCEDURE TDeskScrapView.IDeskScrapView;
-
- VAR
- itsSize: VPoint;
- aPtr: PScrapStuff;
-
- BEGIN
- SetVPt(itsSize, 200, 200);
- { Can't know the extent required until we actually read the data in, which we won't bother
- to do unless forced to by receiving an Update event }
-
- IView(NIL, NIL, gZeroVPt, itsSize, sizeVariable, sizeVariable);
-
- aPtr := InfoScrap;
- fScrapCount := aPtr^.scrapCount - 1;
- fDataHandle := NIL;
- fHavePicture := FALSE;
- fHaveText := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAInit}
-
- PROCEDURE TDeskScrapView.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
-
- VAR
- aPtr: PScrapStuff;
-
- BEGIN
- INHERITED IRes(itsDocument, itsSuperView, itsParams);
-
- aPtr := InfoScrap;
- fScrapCount := aPtr^.scrapCount - 1;
- fDataHandle := NIL;
- fHavePicture := FALSE;
- fHaveText := FALSE;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.Free; OVERRIDE;
-
- BEGIN
- { Never want to free gClipOrphanage. What if some creates another view of this type? }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.CalcMinSize(VAR minSize: VPoint); OVERRIDE;
-
- VAR
- vhs: VHSelect;
- aVRect: VRect;
- aRect: Rect;
- aTEHandle: TEHandle;
- oldHText: Handle;
-
- BEGIN
- minSize := fSize;
- IF fDataHandle <> NIL THEN
- IF fHaveText THEN
- BEGIN { TEXT }
- IF Focus THEN
- BEGIN
- SetPortTextStyle(gSystemStyle);
- fSuperView.GetExtent(aVRect);
- VRectToRect(aVRect, aRect);
- aTEHandle := TENew(aRect, aRect);
- FailNIL(aTEHandle);
-
- WITH aTEHandle^^ DO
- BEGIN
- oldHText := hText; { We'll need this for TEDispose }
- hText := fDataHandle;
- END;
- TECalText(aTEHandle);
- WITH aTEHandle^^ DO
- BEGIN
- minSize.h := aRect.right - aRect.left;
- minSize.v := Min(IntMultiply(nLines, lineHeight), kMaxCoord);
- hText := oldHText; { So TEDispose doesn't dispose our handle }
- END;
-
- TEDispose(aTEHandle);
- END;
- END
-
- ELSE
- BEGIN
- {$IFC qDebug}
- IF gIntenseDebugging THEN
- BEGIN
- Write('Picture Frame:');
- WriteRect(PicHandle(fDataHandle)^^.picFrame);
- END;
- {$ENDC}
-
- FOR vhs := v TO h DO
- IF NOT gVarClipPicSize THEN
- WITH PicHandle(fDataHandle)^^.picFrame DO
- minSize.vh[vhs] := botRight.vh[vhs] - topLeft.vh[vhs];
- END { PICT } ;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.CheckScrapContents;
-
- VAR
- length: LONGINT;
- offset: LONGINT;
- aHandle: Handle;
- resTypeFound: ResType;
- savedPerm: BOOLEAN;
- fi: FailInfo;
-
- PROCEDURE HdlFailure(error: OSErr;
- message: LONGINT);
-
- BEGIN
- aHandle := DisposeIfHandle(aHandle);
- fDataHandle := NIL;
- END;
-
- FUNCTION LookForScrapType(theResType: ResType): BOOLEAN;
-
- VAR
- err: LONGINT;
- offset: LONGINT;
-
- BEGIN
- err := GetScrap(NIL, theResType, offset);
- IF err > 0 THEN
- resTypeFound := theResType;
- {$IFC qDebug}
- IF (err <> noTypeErr) & (err < 0) THEN
- WriteLn('LookForScrapType: err = ', err: 1);
- {$ENDC}
- LookForScrapType := err > 0;
- END;
-
- BEGIN
- IF fScrapCount <> gNewScrapStuff.scrapCount THEN
- BEGIN
-
- { Make sure we get rid of the old scrap handle if necessary }
- fDataHandle := DisposeIfHandle(fDataHandle);
-
- fHavePicture := LookForScrapType('PICT');
- fHaveText := LookForScrapType('TEXT');
-
- IF fHavePicture | fHaveText THEN
- BEGIN
- aHandle := NewPermHandle(0);
- FailNIL(aHandle);
-
- CatchFailures(fi, HdlFailure);
- savedPerm := PermAllocation(TRUE);
- length := GetScrap(aHandle, resTypeFound, offset);
- savedPerm := PermAllocation(savedPerm);
-
- IF length < 0 THEN { Only results < 0 are really errors }
- FailOSErr(length);
- fDataHandle := aHandle;
- AdjustSize;
- IF Focus THEN; { Make sure we're still focused }
- Success(fi);
- END;
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.Draw(area: Rect);
-
- VAR
- aRect: Rect;
- vhs: VHSelect;
-
- BEGIN
- {$IFC qDebug}
- AssumeFocused;
- {$ENDC}
-
- { Has scrap been updated since we last drew? }
- CheckScrapContents;
-
- IF fHaveText THEN
- BEGIN
- SetPortTextStyle(gApplicationStyle);
- GetQDExtent(aRect);
-
- { Does TextEdit handle failure in TextBox??? }
- LockHandleHigh(fDataHandle); { Because MATextBox may move memory }
- MATextBox(fDataHandle^, GetHandleSize(fDataHandle), aRect, teJustSystem,
- kAutoWrap, NIL, kNoEraseFirst, kNoSpaceForCaret);
- HUnlock(fDataHandle);
- END
-
- ELSE IF fHavePicture THEN
-
- BEGIN
- IF gVarClipPicSize THEN
- GetQDExtent(aRect)
- ELSE
- BEGIN
- aRect := PicHandle(fDataHandle)^^.picFrame;
- FOR vhs := v TO h DO
- BEGIN
- aRect.botRight.vh[vhs] := aRect.botRight.vh[vhs] - aRect.topLeft.vh[vhs];
- aRect.topLeft.vh[vhs] := 0;
- END;
- END;
- DrawPicture(PicHandle(fDataHandle), aRect);
- END;
-
- IF fScrapCount <> gNewScrapStuff.scrapCount THEN
- BEGIN
- ValidRect(aRect); { avoid flicker upon clipboard installation
- -- but could this cause failure to update
- frame border/appendages sometimes, if that
- code ever checked for visibility before
- drawing ??? }
- fScrapCount := gNewScrapStuff.scrapCount;
- gClipWrittenToDeskScrap := TRUE; { Don't need to write it back out. }
- END;
-
- INHERITED Draw(area);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAFields}
-
- PROCEDURE TDeskScrapView.Fields(PROCEDURE DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
-
- BEGIN
- DoToField('TDeskScrapView', NIL, bClass);
- DoToField('fHavePicture', @fHavePicture, bBoolean);
- DoToField('fHaveText', @fHaveText, bBoolean);
- DoToField('fScrapCount', @fScrapCount, bInteger);
- DoToField('fDataHandle', @fDataHandle, bHandle);
- INHERITED Fields(DoToField);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAInspector}
-
- PROCEDURE TDeskScrapView.GetInspectorName(VAR inspectorName: Str255); OVERRIDE;
-
- BEGIN
- IF SELF = gClipView THEN
- inspectorName := 'gClipView'
- ELSE IF SELF = gClipOrphanage THEN
- inspectorName := 'gClipOrphanage';
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.SuperViewChangedSize(delta: VPoint;
- invalidate: BOOLEAN); OVERRIDE;
-
- BEGIN
- AdjustSize;
- ForceRedraw;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S MAClipboard}
-
- PROCEDURE TDeskScrapView.WriteToDeskScrap; OVERRIDE;
-
- BEGIN
- { This view represents data that's already written to the desk scrap }
- END;
-